/*
 * @Date: 2023-02-19 11:43:32
 * @LastEditTime: 2023-10-20 21:05:19
 * 介绍:
 */
import { defineStore } from "pinia";
import { localStorage } from "mp-storage";

export default defineStore("SysStore", {
  //*全局仓库
  state: initState,
  //*全局函数
  actions: {
    setRequestBaseData(data: ReqequestBaseData) {
      this.$patch((state) => {
        state.requestBaseData = { ...state.requestBaseData, ...data };
      });
    },
  },
  //*计算属性
  getters: {},
  //*仓库数据缓存
  persist: [
    {
      key: "SysStore",
      storage: localStorage, //指定储存位置
    },
  ],
});
/**state类型定义 */
interface SysStore {
  requestBaseData: ReqequestBaseData;
  setting: Setting;
}
interface Setting {
  authCode?: string;
}
interface ReqequestBaseData {
  _token?: string;
  _agent_id?: number;
}
/**初始化pinia */
function initState(): SysStore {
  return {
    setting: {},
    requestBaseData: {
      _agent_id: 1,
    },
  };
}
